#include <cairo.h>  
#include <gtk/gtk.h>  
   
  
static gboolean  
on_expose_event(GtkWidget *widget,  
    GdkEventExpose *event,  
    gpointer data)  
{  
  cairo_t *cr;  
  cairo_surface_t *surface; 
  cairo_surface_t *image; 
   
  /* 创建cairo的上下文环境 */
  cr = gdk_cairo_create(widget->window);  
  /* 建立并设置源的图片 */
  image = cairo_image_surface_create_from_png("../assert/back.png");  
  cairo_set_source_surface(cr, image, 1, 1);  
  
  /* 设置蒙版 */
  surface = cairo_image_surface_create_from_png("../assert/mask.png");  
  cairo_mask_surface(cr, surface, 0, 0);  
  
  /* 绘制cr中的信息 */
  cairo_fill(cr);  
   
  cairo_surface_destroy(surface);  
  cairo_destroy(cr);  
   
  return FALSE;  
}  
   
   
int main(int argc,char *argv[])  
{  
  GtkWidget *window;  
   
  gtk_init(&argc, &argv);  
   
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  
   
  g_signal_connect(G_OBJECT(window),"expose-event",  
      G_CALLBACK(on_expose_event), NULL);  
  g_signal_connect(G_OBJECT(window),"destroy",  
      G_CALLBACK(gtk_main_quit), NULL);  
   
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);  
  gtk_window_set_default_size(GTK_WINDOW(window), 305, 100);  
   
  gtk_window_set_title(GTK_WINDOW(window),"mask");  
  gtk_widget_set_app_paintable(window, TRUE);  
  gtk_widget_show_all(window);  
   
  gtk_main();  
   
  return 0;  
}  